@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="page-header">
                <h3 class="page-title">
                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
                        <i class="mdi mdi-settings"></i>
                    </span>
                    应用
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">应用管理</a></li>
                        <li class="breadcrumb-item active" aria-current="page">应用列表</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">应用列表</h4>
                            @if(session('admin')->hasSuperRole())
                            <div class="col-lg-9" style="float: left;padding: 0;">
                                <button type="button" class="btn btn-sm btn-gradient-success btn-icon-text" onclick="add()">
                                    <i class="mdi mdi-plus btn-icon-prepend"></i>
                                    添加应用
                                </button>
                            </div>
                            @endif
                            <div class="col-lg-3" style="float: right">
                                <form action="">
                                    <div class="form-group" >
                                        <div class="input-group col-xs-3">
                                            <input type="text" name="wd" class="form-control file-upload-info" placeholder="请输入关键字" value="{{ $wd }}">
                                            <span class="input-group-append">
                                                <button class=" btn btn-sm btn-gradient-primary" type="submit"><i class="mdi mdi-account-search btn-icon-prepend"></i>
                                                    搜索
                                                </button>
                                            </span>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th width="60px;">ID</th>
                                    <th>应用名称</th>
                                    <th>图标</th>
                                    @if(session('admin')->hasSuperRole())
                                    <th>所属用户</th>
                                    @endif
                                    <th>黑名单命中跳转链接</th>
                                    <th>基本操作</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $k=>$v)
                                    <tr>
                                        <td>{{ $v->id }}</td>
                                        <td>
                                            {{ $v->name }}
                                        </td>
                                        <td>
                                            <div>
                                                <img src="{{ $v->icon_url }}" class="config-img" alt="">
                                            </div>
                                        </td>
                                        @if(session('admin')->hasSuperRole())
                                        <td>
                                            <p><span>用户名:</span><span style="color: red">{{ $v->adminUser->account ?? '' }}</span></p>
                                            <p><span>手机号:</span><span style="color: red">{{ $v->mobile ?? '' }}</span></p>
                                        </td>
                                        @endif
                                        <td>{{ $v->redirect_url }}</td>
                                        <td>
                                            <p><a href="/admin/channel/list?app_id={{$v->id}}">短链转化</a></p>
                                            <p><a href="/admin/access-log/list?app_id={{$v->id}}">非法访问拦截记录</a></p>
                                            <p><a href="/admin/statistics/list?app_id={{$v->id}}">拦截记录统计</a></p>
                                            <p><a href="/admin/app/kouzi?app_id={{$v->id}}">口子查询</a></p>
                                            <p><a href="/admin/whitelist/list?app_id={{$v->id}}">白名单管理</a></p>
                                        </td>
                                        <td>{{ $v->created_at }}</td>
                                        <td>
                                            <p>
                                            <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="update({{ $v->id }})">
                                                修改
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button>
                                            </p>
                                            <p>
                                            <button type="button" class="btn btn-sm btn-gradient-danger btn-icon-text" onclick="del({{ $v->id }})">
                                                <i class="mdi mdi-delete btn-icon-prepend"></i>
                                                删除
                                            </button>
                                            </p>
                                            <p>
                                                <a href="/admin/app/puv/{{$v->id}}">
                                                    <button type="button" class="btn btn-sm btn-gradient-danger btn-icon-text">
                                                        <i class="mdi mdi-fan btn-icon-prepend"></i>
                                                        统计
                                                    </button>
                                                </a>
                                            </p>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix">
                                总共 <b>{{ $list->appends(["wd"=>$wd])->total()  }}</b> 条,分为<b>{{ $list->lastPage() }}</b>页
                                {!! $list->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(function(){
            cutStr(50);
        });
        function add(){
            var page = layer.open({
                type: 2,
                title: '添加应用',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/app/add'
            });
        }
        function update(id){
            var page = layer.open({
                type: 2,
                title: '修改应用',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/app/update/'+id
            });
        }
        function del(id){
            myConfirm("删除操作不可逆,是否继续?",function(){
                myRequest("/admin/app/del/"+id,"post",{},function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
        }

        $('.menu-switch').click(function(){
            id = $(this).attr('id');
            state = $(this).attr('state');
            console.log(id)
            console.log(state)
            if(state == "on"){
                $('.pid-'+id).hide();
                $(this).attr("state","off")
                $(this).removeClass('mdi-menu-down').addClass('mdi-menu-right');
            }else{
                $('.pid-'+id).show();
                $(this).attr("state","on")
                $(this).removeClass('mdi-menu-right').addClass('mdi-menu-down');
            }
        })
    </script>
@endsection
